package com.it.springboot_day01demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.it.springboot_day01demo.bean.Emp;
import com.it.springboot_day01demo.bean.User;
import com.it.springboot_day01demo.mapper.UserMapper;
import com.it.springboot_day01demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils.eq;

@Service
@Transactional
public class UserServiceImp implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * @Cacheabble("selectAllUserList")注解中的selectAllUserList
     * 在Redis缓存中开启了一个名为selectAllUserlist的缓存区域，缓存区域中存储的就是查询的用户列表
     * @return
     */
    @Override
    //@Cacheable("selectAllUserList")
    public List<User> selectAllUserList() {
        Wrapper<User> wrapper = new QueryWrapper<>();
        //((QueryWrapper<User>)wrapper).like("ename","红");
        //((QueryWrapper<User>)wrapper).eq("id",5);
        //System.out.println("若第二次没有输出此句话，说明没有执行此方法，即从缓存中获取数据");
        return userMapper.selectList(null);
    }

    @Override
    public int updateUserById(User user) {
        //update emp
        return userMapper.updateById(user);
    }

    @Override
    public int deleteUserById(int usid) {
        return userMapper.deleteById(usid);
    }

    @Override
    public User selectUserById(int id) {
        return userMapper.selectById(id);
    }
}
